﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.Configuration;
using System.Configuration;

namespace NetFrameworkExtensions.Enterprise.EL5
{
  public class AppConfigUnityBootstrapper : 
    UnityBootstrapper
  {
    public string ConfigName { get; protected set; }

    public AppConfigUnityBootstrapper()
    {
    }

    public AppConfigUnityBootstrapper(string configName)
    {
      this.ConfigName = configName;
    }

    protected override void ConfigureContainer(IUnityContainer unityContainer)
    {
      var section = (UnityConfigurationSection)ConfigurationManager.GetSection("unity");
      
      if (string.IsNullOrEmpty(ConfigName))
        section.Configure(unityContainer);
      else
        section.Configure(unityContainer, ConfigName);

      base.ConfigureContainer(unityContainer);
    }
  }
}
